﻿using System;
using System.Collections.Generic;
using System.Linq;
using Character;
using IllusionUtility.GetUtility;
using UnityEngine;

namespace Studio
{
	// Token: 0x0200044B RID: 1099
	public class FKCtrl : MonoBehaviour
	{
		// Token: 0x170002AF RID: 687
		// (get) Token: 0x06001B6A RID: 7018 RVA: 0x000B0BD8 File Offset: 0x000AEDD8
		private new Transform transform
		{
			get
			{
				if (this.m_Transform == null)
				{
					this.m_Transform = base.transform;
				}
				return this.m_Transform;
			}
		}

		// Token: 0x06001B6B RID: 7019 RVA: 0x000B0C00 File Offset: 0x000AEE00
		public void InitBones(OICharInfo _info, ChaControl _charCtrl)
		{
			if (_info == null)
			{
				return;
			}
			this.oicinfo = _info;
			this.charCtrl = _charCtrl;
			this.listBones.Clear();
			foreach (KeyValuePair<int, Info.BoneInfo> keyValuePair in ((_info.sex != 1) ? Singleton<Info>.Instance.dicMaleBoneInfo : Singleton<Info>.Instance.dicFemaleBoneInfo))
			{
				OIBoneInfo oiboneInfo = null;
				if (_info.bones.TryGetValue(keyValuePair.Key, out oiboneInfo))
				{
					switch (keyValuePair.Value.group)
					{
					case 7:
					case 8:
					case 9:
					{
						HAIR_TYPE[] array = new HAIR_TYPE[]
						{
							HAIR_TYPE.FRONT,
							HAIR_TYPE.BACK,
							HAIR_TYPE.SIDE
						};
						GameObject obj = _charCtrl.human.hairs.GetObj(array[keyValuePair.Value.group - 7]);
						if (!(obj == null))
						{
							this.listBones.Add(new FKCtrl.HairInfo(keyValuePair.Value.bone, obj, oiboneInfo.changeAmount, this.Convert(keyValuePair.Value.group), keyValuePair.Value.level));
						}
						break;
					}
					default:
					{
						GameObject gameObject = this.transform.FindLoop(keyValuePair.Value.bone);
						if (gameObject == null)
						{
							GlobalData.Debug_LogWarning(keyValuePair.Value.bone);
						}
						this.listBones.Add(new FKCtrl.GenericInfo(gameObject, oiboneInfo.changeAmount, this.Convert(keyValuePair.Value.group), keyValuePair.Value.level));
						break;
					}
					}
				}
			}
		}

		// Token: 0x06001B6C RID: 7020 RVA: 0x000B0DE8 File Offset: 0x000AEFE8
		public void InitBones(OICharInfo _info, ChaControl _charCtrl, OIBoneInfo.BoneGroup _group)
		{
			if (_info == null)
			{
				return;
			}
			this.listBones.RemoveAll((FKCtrl.TargetInfo v) => (v.group & _group) != (OIBoneInfo.BoneGroup)0);
			foreach (KeyValuePair<int, Info.BoneInfo> keyValuePair in from v in (_info.sex != 1) ? Singleton<Info>.Instance.dicMaleBoneInfo : Singleton<Info>.Instance.dicFemaleBoneInfo
			where (this.Convert(v.Value.@group) & _group) != (OIBoneInfo.BoneGroup)0
			select v)
			{
				OIBoneInfo oiboneInfo = null;
				if (_info.bones.TryGetValue(keyValuePair.Key, out oiboneInfo))
				{
					switch (keyValuePair.Value.group)
					{
					case 7:
					case 8:
					case 9:
					{
						HAIR_TYPE[] array = new HAIR_TYPE[]
						{
							HAIR_TYPE.FRONT,
							HAIR_TYPE.BACK,
							HAIR_TYPE.SIDE
						};
						GameObject obj = _charCtrl.human.hairs.GetObj(array[keyValuePair.Value.group - 7]);
						if (!(obj == null))
						{
							this.listBones.Add(new FKCtrl.HairInfo(keyValuePair.Value.bone, obj, oiboneInfo.changeAmount, this.Convert(keyValuePair.Value.group), keyValuePair.Value.level));
						}
						break;
					}
					default:
					{
						GameObject gameObject = this.transform.FindLoop(keyValuePair.Value.bone);
						if (gameObject == null)
						{
							GlobalData.Debug_LogWarning(keyValuePair.Value.bone);
						}
						else
						{
							this.listBones.Add(new FKCtrl.GenericInfo(gameObject, oiboneInfo.changeAmount, this.Convert(keyValuePair.Value.group), keyValuePair.Value.level));
						}
						break;
					}
					}
				}
			}
		}

		// Token: 0x06001B6D RID: 7021 RVA: 0x000B0FF8 File Offset: 0x000AF1F8
		public void CopyBone()
		{
			foreach (FKCtrl.TargetInfo targetInfo in this.listBones)
			{
				targetInfo.CopyBone();
			}
		}

		// Token: 0x06001B6E RID: 7022 RVA: 0x000B1054 File Offset: 0x000AF254
		public void CopyBone(OIBoneInfo.BoneGroup _target)
		{
			foreach (FKCtrl.TargetInfo targetInfo in from x in this.listBones
			where (x.@group & _target) != (OIBoneInfo.BoneGroup)0
			select x)
			{
				targetInfo.CopyBone();
			}
		}

		// Token: 0x06001B6F RID: 7023 RVA: 0x000B10CC File Offset: 0x000AF2CC
		public void SetEnable(OIBoneInfo.BoneGroup _group, bool _enable)
		{
			foreach (FKCtrl.TargetInfo targetInfo in from x in this.listBones
			where (x.@group & _group) != (OIBoneInfo.BoneGroup)0
			select x)
			{
				targetInfo.enable = _enable;
			}
			if ((OIBoneInfo.BoneGroup.Hair & _group) != (OIBoneInfo.BoneGroup)0 && _enable)
			{
				this.InitBones(this.oicinfo, this.charCtrl, OIBoneInfo.BoneGroup.Hair);
			}
		}

		// Token: 0x06001B70 RID: 7024 RVA: 0x000B1174 File Offset: 0x000AF374
		private OIBoneInfo.BoneGroup Convert(int _group)
		{
			switch (_group)
			{
			case 0:
			case 1:
			case 2:
			case 3:
			case 4:
				return OIBoneInfo.BoneGroup.Body;
			case 7:
			case 8:
			case 9:
				return OIBoneInfo.BoneGroup.Hair;
			case 10:
				return OIBoneInfo.BoneGroup.Neck;
			case 11:
			case 12:
				return OIBoneInfo.BoneGroup.Breast;
			case 13:
				return OIBoneInfo.BoneGroup.Skirt;
			}
			return (OIBoneInfo.BoneGroup)(1 << _group);
		}

		// Token: 0x06001B71 RID: 7025 RVA: 0x000B11E4 File Offset: 0x000AF3E4
		private void LateUpdate()
		{
			foreach (FKCtrl.TargetInfo targetInfo in this.listBones)
			{
				targetInfo.Update();
			}
		}

		// Token: 0x04001EE4 RID: 7908
		public static OIBoneInfo.BoneGroup[] parts = new OIBoneInfo.BoneGroup[]
		{
			OIBoneInfo.BoneGroup.Hair,
			OIBoneInfo.BoneGroup.Neck,
			OIBoneInfo.BoneGroup.Breast,
			OIBoneInfo.BoneGroup.Body,
			OIBoneInfo.BoneGroup.RightHand,
			OIBoneInfo.BoneGroup.LeftHand,
			OIBoneInfo.BoneGroup.Skirt
		};

		// Token: 0x04001EE5 RID: 7909
		private Transform m_Transform;

		// Token: 0x04001EE6 RID: 7910
		private List<FKCtrl.TargetInfo> listBones = new List<FKCtrl.TargetInfo>();

		// Token: 0x04001EE7 RID: 7911
		private OICharInfo oicinfo;

		// Token: 0x04001EE8 RID: 7912
		private ChaControl charCtrl;

		// Token: 0x0200044C RID: 1100
		private abstract class TargetInfo
		{
			// Token: 0x06001B73 RID: 7027 RVA: 0x000B1258 File Offset: 0x000AF458
			public TargetInfo(GameObject _gameObject, ChangeAmount _changeAmount, OIBoneInfo.BoneGroup _group, int _level)
			{
				this.gameObject = _gameObject;
				this.changeAmount = _changeAmount;
				this.group = _group;
				this.level = _level;
			}

			// Token: 0x170002B0 RID: 688
			// (get) Token: 0x06001B74 RID: 7028 RVA: 0x000B1284 File Offset: 0x000AF484
			// (set) Token: 0x06001B75 RID: 7029 RVA: 0x000B128C File Offset: 0x000AF48C
			public GameObject gameObject { get; private set; }

			// Token: 0x170002B1 RID: 689
			// (get) Token: 0x06001B76 RID: 7030 RVA: 0x000B1298 File Offset: 0x000AF498
			public virtual Transform transform
			{
				get
				{
					if (this._transform == null)
					{
						this._transform = this.gameObject.transform;
					}
					return this._transform;
				}
			}

			// Token: 0x170002B2 RID: 690
			// (get) Token: 0x06001B77 RID: 7031 RVA: 0x000B12C4 File Offset: 0x000AF4C4
			// (set) Token: 0x06001B78 RID: 7032 RVA: 0x000B12CC File Offset: 0x000AF4CC
			public OIBoneInfo.BoneGroup group { get; private set; }

			// Token: 0x170002B3 RID: 691
			// (get) Token: 0x06001B79 RID: 7033 RVA: 0x000B12D8 File Offset: 0x000AF4D8
			// (set) Token: 0x06001B7A RID: 7034 RVA: 0x000B12E0 File Offset: 0x000AF4E0
			public int level { get; private set; }

			// Token: 0x06001B7B RID: 7035 RVA: 0x000B12EC File Offset: 0x000AF4EC
			public void CopyBone()
			{
				if (this.transform != null)
				{
					this.changeAmount.rot = this.transform.localEulerAngles;
				}
			}

			// Token: 0x06001B7C RID: 7036 RVA: 0x000B1318 File Offset: 0x000AF518
			public void Update()
			{
				if (this.enable && this.transform != null)
				{
					this.transform.localRotation = Quaternion.Euler(this.changeAmount.rot);
				}
			}

			// Token: 0x04001EEA RID: 7914
			protected Transform _transform;

			// Token: 0x04001EEB RID: 7915
			public ChangeAmount changeAmount;

			// Token: 0x04001EEE RID: 7918
			public bool enable = true;
		}

		// Token: 0x0200044D RID: 1101
		private class GenericInfo : FKCtrl.TargetInfo
		{
			// Token: 0x06001B7D RID: 7037 RVA: 0x000B1354 File Offset: 0x000AF554
			public GenericInfo(GameObject _gameObject, ChangeAmount _changeAmount, OIBoneInfo.BoneGroup _group, int _level) : base(_gameObject, _changeAmount, _group, _level)
			{
			}
		}

		// Token: 0x0200044E RID: 1102
		private class HairInfo : FKCtrl.TargetInfo
		{
			// Token: 0x06001B7E RID: 7038 RVA: 0x000B1364 File Offset: 0x000AF564
			public HairInfo(string _bone, GameObject _root, ChangeAmount _changeAmount, OIBoneInfo.BoneGroup _group, int _level) : base(_root, _changeAmount, _group, _level)
			{
				this.name = _bone;
			}

			// Token: 0x170002B4 RID: 692
			// (get) Token: 0x06001B7F RID: 7039 RVA: 0x000B1384 File Offset: 0x000AF584
			public override Transform transform
			{
				get
				{
					if (this._transform == null)
					{
						GameObject gameObject = base.gameObject.transform.FindLoop(this.name);
						this._transform = ((!(gameObject != null)) ? null : gameObject.transform);
					}
					return this._transform;
				}
			}

			// Token: 0x04001EEF RID: 7919
			private string name = string.Empty;
		}
	}
}
